package com.yh.csx.bsf.flow.dao.dal.auto;

import java.util.ArrayList;
import java.util.Map;
import java.util.List;

import com.yh.csx.bsf.flow.core.db.ConvertUtil;
import com.yh.csx.bsf.flow.core.db.DbConn;
import com.yh.csx.bsf.flow.dao.model.auto.*;

/** 代码自动生成工具自动生成,不要在这里写自己的代码，否则会被自动覆盖哦 - 车毅*/
public class t_flow_base_dal
{
    public boolean add(DbConn conn, t_flow_model model)
    {
		Object[] Par = new Object[]{
		
		//
		model.title,
		//
		model.approve_node,
		//
		model.approve_userno,
		//
		model.approve_by,
		//
		model.flow_state,
		//
		model.flow_variable_json,
		//
		model.model_id,
		//
		model.model_name,
		//
		model.model_title,
		//
		model.model_version,
		//
		model.create_userno,
		//
		model.update_time,
		//
		model.update_by,
		//
		model.create_time,
		//
		model.create_by,
		//
		model.flow_error
		};
        int rev = conn.executeSql("insert into t_flow(title,approve_node,approve_userno,approve_by,flow_state,flow_variable_json,model_id,model_name,model_title,model_version,create_userno,update_time,update_by,create_time,create_by,flow_error)"+
										"values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", Par);
        return rev == 1;

    }

    public boolean edit(DbConn conn, t_flow_model model)
    {
        ArrayList<Object> Par = new ArrayList<Object>();
        
		//
		Par.add(model.title);
		//
		Par.add(model.approve_node);
		//
		Par.add(model.approve_userno);
		//
		Par.add(model.approve_by);
		//
		Par.add(model.flow_state);
		//
		Par.add(model.flow_variable_json);
		//
		Par.add(model.model_id);
		//
		Par.add(model.model_name);
		//
		Par.add(model.model_title);
		//
		Par.add(model.model_version);
		//
		Par.add(model.create_userno);
		//
		Par.add(model.update_time);
		//
		Par.add(model.update_by);
		//
		Par.add(model.create_time);
		//
		Par.add(model.create_by);
		//
		Par.add(model.flow_error);
		Par.add(model.id);

        int rev = conn.executeSql("update t_flow set title=?,approve_node=?,approve_userno=?,approve_by=?,flow_state=?,flow_variable_json=?,model_id=?,model_name=?,model_title=?,model_version=?,create_userno=?,update_time=?,update_by=?,create_time=?,create_by=?,flow_error=? where id=?",  Par.toArray());
        return rev == 1;

    }

    public boolean delete(DbConn conn, int id)
    {
        ArrayList<Object> Par = new ArrayList<Object>();
        Par.add(id);

        String Sql = "delete from t_flow where id=?";
        int rev = conn.executeSql(Sql, Par.toArray());
        if (rev == 1)
        {
            return true;
        }
        else
        {
            return false;
        }

    }

    public t_flow_model get(DbConn conn, int id)
    {
        ArrayList<Object> Par = new ArrayList<Object>();
        Par.add(id);
        StringBuilder stringSql = new StringBuilder();
        stringSql.append("select s.* from t_flow s where s.id=?");
        List<Map<String,Object>> ds = conn.executeList(stringSql.toString(), Par.toArray());
        if (ds != null && ds.size() > 0)
        {
			return createModel(ds.get(0));
        }
        return null;
    }

	public ArrayList<t_flow_model> list(DbConn conn)
    {
		ArrayList<t_flow_model> rs = new ArrayList<t_flow_model>();
        StringBuilder stringSql = new StringBuilder();
        stringSql.append("select s.* from t_flow s ");
        List<Map<String,Object>> ds = conn.executeList(stringSql.toString(), new Object[]{});
        if (ds != null && ds.size() > 0)
        {
			for (Map<String,Object> dr : ds)
			{
				rs.add(createModel(dr));
			}
        }
        return rs;
    }

	public t_flow_model createModel(Map<String,Object> dr)
    {
        t_flow_model o = new t_flow_model();
		
		//
		if(dr.containsKey("id"))
		{
			o.id = ConvertUtil.objToInt(dr.get("id"));
		}
		//
		if(dr.containsKey("title"))
		{
			o.title = ConvertUtil.objToStr(dr.get("title"));
		}
		//
		if(dr.containsKey("approve_node"))
		{
			o.approve_node = ConvertUtil.objToStr(dr.get("approve_node"));
		}
		//
		if(dr.containsKey("approve_userno"))
		{
			o.approve_userno = ConvertUtil.objToStr(dr.get("approve_userno"));
		}
		//
		if(dr.containsKey("approve_by"))
		{
			o.approve_by = ConvertUtil.objToStr(dr.get("approve_by"));
		}
		//
		if(dr.containsKey("flow_state"))
		{
			o.flow_state = ConvertUtil.objToByte(dr.get("flow_state"));
		}
		//
		if(dr.containsKey("flow_variable_json"))
		{
			o.flow_variable_json = ConvertUtil.objToStr(dr.get("flow_variable_json"));
		}
		//
		if(dr.containsKey("model_id"))
		{
			o.model_id = ConvertUtil.objToInt(dr.get("model_id"));
		}
		//
		if(dr.containsKey("model_name"))
		{
			o.model_name = ConvertUtil.objToStr(dr.get("model_name"));
		}
		//
		if(dr.containsKey("model_title"))
		{
			o.model_title = ConvertUtil.objToStr(dr.get("model_title"));
		}
		//
		if(dr.containsKey("model_version"))
		{
			o.model_version = ConvertUtil.objToInt(dr.get("model_version"));
		}
		//
		if(dr.containsKey("create_userno"))
		{
			o.create_userno = ConvertUtil.objToStr(dr.get("create_userno"));
		}
		//
		if(dr.containsKey("update_time"))
		{
			o.update_time = ConvertUtil.objToDateTime(dr.get("update_time"));
		}
		//
		if(dr.containsKey("update_by"))
		{
			o.update_by = ConvertUtil.objToStr(dr.get("update_by"));
		}
		//
		if(dr.containsKey("create_time"))
		{
			o.create_time = ConvertUtil.objToDateTime(dr.get("create_time"));
		}
		//
		if(dr.containsKey("create_by"))
		{
			o.create_by = ConvertUtil.objToStr(dr.get("create_by"));
		}
		//
		if(dr.containsKey("flow_error"))
		{
			o.flow_error = ConvertUtil.objToStr(dr.get("flow_error"));
		}
		return o;
    }
}
